<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <style>
        .select {
            border: 1px solid #bdb2b2;
            border-radius: 10px;
            /*清除select聚焦时候的边框颜色*/
            outline: none;
            /*设置select的宽高*/
            width: 200px;
            height: 40px;
            line-height: 40px;
            /*隐藏select的下拉图标*/
            appearance: none;
            -webkit-appearance: none;
            -moz-appearance: none;
            /*通过padding-left的值让文字处于合适位置*/
            padding-left: 20px;
            /* 设置下拉图标 */
        }
    </style>
</head>
<body>
over_time:
<select id="over_time" class="select">
    <option>5</option>
    <option>10</option>
    <option>30</option>
    <option>60</option>
    <option>120</option>
</select><br>
text_name:
<select id="sel" class="select"></select><br>
<button id="button">button</button>
<br>


<div id="d"></div>
<script>
    var sel = document.getElementById("sel");
    var f = document.getElementById('d')


    $.ajax({
        type: "POST",
        url: "/topic",
        success: function (message) {
            console.log(message)
            console.log("提交成功");
            var topic = message['topic']
            for (var i in topic) {
                console.log(i, topic[i])
                var opt = document.createElement("option");
                opt.innerHTML = topic[i]
                sel.appendChild(opt);
            }
        },
        error: function (message) {
            alert("提交失败");
        }
    });

    $("#sel").change(function () {
        //要触发的事件
        $.ajax({
            type: "POST",
            url: "/topictext",
            data: {
                value: sel.options[sel.selectedIndex].text,
            },
            success: function (message) {

                console.log(message)
                console.log("提交成功");
                for (var i in message) {
                    console.log(i, message[i])
                    f.innerText = message[i]
                }
                console.log('---------')
                console.log(message[0])

            },
            error: function (message) {
                alert("提交失败");
            }
        });
    });

    $("#button").click(function () {
        $.ajax({
            url: '/upload',
            type: "POST",
            dataType: 'json',
            data: {
                over_time: $("#over_time").val(),
                text_name: sel.options[sel.selectedIndex].text,
            },
            success: function (result) {
                alert('cg')
                console.log(result)
                window.open('/index', '_self')

            },
            error: function () {
                window.open('/index', '_self')
                console.log('shibai')
            },
        });
    })

</script>
</body>
</html>